#extension GL_EXT_gpu_shader4 : enable

uniform sampler2D BjSampler;
uniform sampler2D deltaBjSampler;
uniform sampler2D shooterDeltaBjSampler;

uniform vec3 ro;
uniform vec2 shooterDeltaBjTexCoords;
uniform float shooterFaceArea;
uniform int shooterLevel;

float FormFactor(float shooterDeltaArea);

void main(void)
{
	ivec2 shooterTextureSize = textureSize2D(shooterDeltaBjSampler, shooterLevel);
	float shooterTextureArea = float(shooterTextureSize.x * shooterTextureSize.y);
	float shooterDeltaArea = shooterFaceArea / shooterTextureArea;

	vec4 Bj = texture2D(BjSampler, gl_TexCoord[0].st);
	vec4 deltaBj = texture2D(deltaBjSampler, gl_TexCoord[0].st);
	vec3 shootDeltaBj = texture2D(shooterDeltaBjSampler, shooterDeltaBjTexCoords, float(shooterLevel)).rgb;

	float Fij = FormFactor(shooterDeltaArea);
	vec4 shotRadiosity = shooterDeltaArea * vec4(ro * shootDeltaBj * Fij, 1);

	gl_FragData[0] = Bj + shotRadiosity;
	gl_FragData[1] = deltaBj + shotRadiosity;
}
